//
//  DetailsListViewController.m
//  Comma
//
//  Created by dlios on 15-1-13.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//
#import "DetailsListViewController.h"
#import "DetailsListView.h"
#import "ImageShowViewController.h"
#import "CustomTableViewCell.h"
#import "OnlyImageTableViewCell.h"
#import "OnlyTextTableViewCell.h"
#import "TextAndImageTableViewCell.h"
#import "AFNetWorkingYU.h"
#import "UIImageView+WebCache.h"
#import "GlobalMethod.h"
#import "URLMacro.h"
#import "HiddenView.h"
#import "DetailViewController.h"
#import "CategoryViewController.h"
#import "HelpViewController.h"
#import "SettingsViewController.h"
#import "PersonalCenterViewController.h"
#import "MyDynamicViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "CustomView.h"
#import "ReleaseViewController.h"
#import "YRSideViewController.h"
#import "CategoryView.h"
#import "GlobalMacro.h"
#import "NotificationViewController.h"
#import "LoadIndicator.h"
#import "CategoryView.h"
#import "OtherPersonViewController.h"
#import "DetailModel.h"
#import "OtherModel.h"
#import "MJRefresh.h"
#import "MJRefreshHeaderView.h"
#import <CoreText/CoreText.h>
#import "LoadIndicator.h"
#import "Reachability.h"
#import "MJRefreshFooterView.h"


@interface DetailsListViewController ()<UITableViewDataSource, UITableViewDelegate, OnlyImageTableViewCellDelegate, OnlyTextTableViewCellDelegate, TextAndImageTableViewCellDelegate>
@property (nonatomic, assign)NSInteger index;
@property (nonatomic, strong)LoadIndicator *load; //小棍棍
@end

@implementation DetailsListViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tableArray = [NSMutableArray array];
        self.otherArray = [NSMutableArray array];
        self.load = [[LoadIndicator alloc] init];
        self.index = 1;
        self.category = nil;
        self.categoryIsShow = NO;
        self.hiddenIsShow = NO;
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    YRSideViewController * sideview = [YRSideViewController share];
    sideview.needSwipeShowMenu= YES;
    
    //每次视图出现的时候都要调用  看看是否有未读消息或者留言，实时刷新
    if (self.detailsListView.changeMail) {
        [self getUnreadMessageNumber];
    }
<<<<<<< HEAD
    //重新网络请求
    NSString *approveKey= [GlobalMethod GetIOSUUID];
    NSString *deviceParam = [GlobalMethod getApproveKey];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *userId = [user objectForKey:@"id"];
    NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];
    [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
        [self.tableArray removeAllObjects];
        [self.otherArray removeAllObjects];
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
        NSArray *dataArray = [dic objectForKey:@"dataGrid"];
        for (NSDictionary *myDic in dataArray) {
            self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
            [self.tableArray addObject:self.listModel];
        }
        NSArray *otherArr = [dic objectForKey:@"other"];
        for (NSDictionary *myDic in otherArr) {
            self.otherDic = myDic;
            [self.otherArray addObject:self.otherDic];
        }
        [self.detailsListView.tableView reloadData];
    }];
=======
    
>>>>>>> ac86f249d4ffb2191dbbb920ed1d003a12685fcc
}

- (void)loadView
{
    [super loadView];
    YRSideViewController * sideview = [YRSideViewController share];
    //侧边栏设置不滑动出现
    sideview.needSwipeShowMenu= YES;
    // 请求数据完成创建视图
    self.detailsListView = [[DetailsListView alloc] initWithLeftButton:@"类别" RightButton:@"定向" Title:nil FooterView:FooterViewStateNormal];
    [self.view addSubview:_detailsListView];
    [self.load addLoadView:self.detailsListView];
    if (iPhone6Plus) {
        self.categoryView = [[CategoryView alloc] initWithFrame:CGRectMake(0, 96, SCREEN_WIDTH, 0)];
    }
    else {
        self.categoryView = [[CategoryView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 0)];
    }
    for (int i = 0; i < 13; i++) {
        UIButton *button = (UIButton *)[self.categoryView viewWithTag:10 + i];
        [button addTarget:self action:@selector(cateButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    [self.detailsListView addSubview:_categoryView];
    self.fontView = [[UIView alloc] init];
    [_fontView setClipsToBounds:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [_tableArray removeAllObjects];
//    [_otherArray removeAllObjects];
    [self startConnect];

    // 注册通知
    [self.detailsListView.leftButton addTarget:self action:@selector(categoryButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.detailsListView.rightButton addTarget:self action:@selector(derectionButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.detailsListView.footerButton addTarget:self action:@selector(publishButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

// 通知重新网络请求
- (void)reConnect
{
    //重新网络请求
    [self.tableArray removeAllObjects];
    [self.otherArray removeAllObjects];
    NSString *approveKey= [GlobalMethod GetIOSUUID];
    NSString *deviceParam = [GlobalMethod getApproveKey];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *userId = [user objectForKey:@"id"];
    NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];
    [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
        NSArray *dataArray = [dic objectForKey:@"dataGrid"];
        for (NSDictionary *myDic in dataArray) {
            self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
            [self.tableArray addObject:self.listModel];
        }
        NSArray *otherArr = [dic objectForKey:@"other"];
        for (NSDictionary *myDic in otherArr) {
            self.otherDic = myDic;
            [self.otherArray addObject:self.otherDic];
        }
        [self.detailsListView.tableView reloadData];
    }];
}


#pragma mark - 按钮点击事件
// 点赞
- (void)OnlyImagePressReturn:(NSString *)infoId good:(NSNumber *)good bad:(NSNumber *)bad cell:(OnlyImageTableViewCell *)cell
{
    NSString *approveKey= [GlobalMethod GetIOSUUID];
    NSString *deviceParam = [GlobalMethod getApproveKey];
    NSString *body = [NSString stringWithFormat:@"infoId=%@&approveKey=%@&deviceParam=%@", infoId, approveKey, deviceParam];
    [AFNetWorkingYU netWorkWithURL:URL_ISUSO_GOOD body:body resultBlock:^(id result) {
        if ([result isKindOfClass:[NSDictionary class]]) {
            NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
            NSString *str = [dic objectForKey:@"msg"];
            if ([str isEqualToString:@"点赞成功"]) {
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall_effect(1)"] forState:UIControlStateNormal];
            } else if ([str isEqualToString:@"取消成功"]) {
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall(1)"] forState:UIControlStateNormal];
            }
            
            //重新网络请求
            [self.tableArray removeAllObjects];
            [self.otherArray removeAllObjects];
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString *userId = [user objectForKey:@"id"];
            NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];
            [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
                NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
                NSArray *dataArray = [dic objectForKey:@"dataGrid"];
                for (NSDictionary *myDic in dataArray) {
                    self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
                    [self.tableArray addObject:self.listModel];
                }
                NSArray *otherArr = [dic objectForKey:@"other"];
                for (NSDictionary *myDic in otherArr) {
                    self.otherDic = myDic;
                    [self.otherArray addObject:self.otherDic];
                }
                [self.detailsListView.tableView reloadData];
            }];
        }
        else
        {
            [self aleareViewWithString:@"操作失败"];
        }
        
    }];
}

- (void)OnlyTextPressReturn:(NSString *)infoId good:(NSNumber *)good bad:(NSNumber *)bad cell:(OnlyTextTableViewCell *)cell
{
    NSString *approveKey= [GlobalMethod GetIOSUUID];
    NSString *deviceParam = [GlobalMethod getApproveKey];
    
    NSString *body = [NSString stringWithFormat:@"infoId=%@&approveKey=%@&deviceParam=%@", infoId, approveKey, deviceParam];
    [AFNetWorkingYU netWorkWithURL:URL_ISUSO_GOOD body:body resultBlock:^(id result) {
        if ([result isKindOfClass:[NSDictionary class]]) {
            
            NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
            NSString *str = [dic objectForKey:@"msg"];
            if ([str isEqualToString:@"点赞成功"]) {
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall_effect(1)"] forState:UIControlStateNormal];
            } else if ([str isEqualToString:@"取消成功"]) {
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall(1)"] forState:UIControlStateNormal];
            }
            
            //重新网络请求
            [self.tableArray removeAllObjects];
            [self.otherArray removeAllObjects];
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString *userId = [user objectForKey:@"id"];
            //    NSString *approveKey= [GlobalMethod GetIOSUUID];
            //    NSString *deviceParam = [GlobalMethod getApproveKey];
            NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];
            [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
                NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
                NSArray *dataArray = [dic objectForKey:@"dataGrid"];
                for (NSDictionary *myDic in dataArray) {
                    self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
                    [self.tableArray addObject:self.listModel];
                }
                NSArray *otherArr = [dic objectForKey:@"other"];
                for (NSDictionary *myDic in otherArr) {
                    self.otherDic = myDic;
                    [self.otherArray addObject:self.otherDic];
                }
                [self.detailsListView.tableView reloadData];
            }];
        }
        else
        {
            [self aleareViewWithString:@"操作失败"];
        }
        
    }];}

- (void)TextAndImagePressReturn:(NSString *)infoId good:(NSNumber *)good bad:(NSNumber *)bad cell:(TextAndImageTableViewCell *)cell
{
    NSString *approveKey= [GlobalMethod GetIOSUUID];
    NSString *deviceParam = [GlobalMethod getApproveKey];
    
    NSString *body = [NSString stringWithFormat:@"infoId=%@&approveKey=%@&deviceParam=%@", infoId, approveKey, deviceParam];
    [AFNetWorkingYU netWorkWithURL:URL_ISUSO_GOOD body:body resultBlock:^(id result) {
        if ([result isKindOfClass:[NSDictionary class]]) {
            
            NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
            NSString *str = [dic objectForKey:@"msg"];
            if ([str isEqualToString:@"点赞成功"]) {
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall_effect(1)"] forState:UIControlStateNormal];
            } else if ([str isEqualToString:@"取消成功"]) {
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall(1)"] forState:UIControlStateNormal];
            }
        
            //重新网络请求
            [self.tableArray removeAllObjects];
            [self.otherArray removeAllObjects];
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString *userId = [user objectForKey:@"id"];
            //    NSString *approveKey= [GlobalMethod GetIOSUUID];
            //    NSString *deviceParam = [GlobalMethod getApproveKey];
            NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];
            [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
                NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
                NSArray *dataArray = [dic objectForKey:@"dataGrid"];
                for (NSDictionary *myDic in dataArray) {
                    self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
                    [self.tableArray addObject:self.listModel];
                }
                NSArray *otherArr = [dic objectForKey:@"other"];
                for (NSDictionary *myDic in otherArr) {
                    self.otherDic = myDic;
                    [self.otherArray addObject:self.otherDic];
                }
                [self.detailsListView.tableView reloadData];
            }];
        }
        else
        {
            [self aleareViewWithString:@"操作失败"];
        }
        
    }];
}
// 点踩实现
- (void)TextAndImageTrampleReturn:(NSString *)infoId good:(NSNumber *)good bad:(NSNumber *)bad cell:(TextAndImageTableViewCell *)cell
{
    NSString *approveKey= [GlobalMethod GetIOSUUID];
    NSString *deviceParam = [GlobalMethod getApproveKey];
    NSString *body = [NSString stringWithFormat:@"infoId=%@&approveKey=%@&deviceParam=%@", infoId, approveKey, deviceParam];
    [AFNetWorkingYU netWorkWithURL:URL_ISUSO_BAD body:body resultBlock:^(id result) {
        if ([result isKindOfClass:[NSDictionary class]]) {
            NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
            NSString *str = [dic objectForKey:@"msg"];
            if ([str isEqualToString:@"点赞成功"]) {
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall_leffect(1)"] forState:UIControlStateNormal];
            } else if ([str isEqualToString:@"取消成功"]) {
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall(1)"] forState:UIControlStateNormal];
            }
            
            //重新网络请求
            [self.tableArray removeAllObjects];
            [self.otherArray removeAllObjects];
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString *userId = [user objectForKey:@"id"];
            NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];
            [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
                NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
                NSArray *dataArray = [dic objectForKey:@"dataGrid"];
                for (NSDictionary *myDic in dataArray) {
                    self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
                    [self.tableArray addObject:self.listModel];
                }
                NSArray *otherArr = [dic objectForKey:@"other"];
                for (NSDictionary *myDic in otherArr) {
                    self.otherDic = myDic;
                    [self.otherArray addObject:self.otherDic];
                }
                [self.detailsListView.tableView reloadData];
            }];
        }
        else
        {
            [self aleareViewWithString:@"操作失败"];
        }
    }
  ];
}

- (void)OnlyTextTrampleReturn:(NSString *)infoId good:(NSNumber *)good bad:(NSNumber *)bad cell:(OnlyTextTableViewCell *)cell{
    NSString *approveKey= [GlobalMethod GetIOSUUID];
    NSString *deviceParam = [GlobalMethod getApproveKey];
    NSString *body = [NSString stringWithFormat:@"infoId=%@&approveKey=%@&deviceParam=%@", infoId, approveKey, deviceParam];
    [AFNetWorkingYU netWorkWithURL:URL_ISUSO_BAD body:body resultBlock:^(id result) {
        if ([result isKindOfClass:[NSDictionary class]]) {
            
            NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
            NSString *str = [dic objectForKey:@"msg"];
            if ([str isEqualToString:@"点赞成功"]) {
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall_leffect(1)"] forState:UIControlStateNormal];
            } else if ([str isEqualToString:@"取消成功"]) {
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall(1)"] forState:UIControlStateNormal];
            }
            //重新网络请求
            [self.tableArray removeAllObjects];
            [self.otherArray removeAllObjects];
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString *userId = [user objectForKey:@"id"];
            //    NSString *approveKey= [GlobalMethod GetIOSUUID];
            //    NSString *deviceParam = [GlobalMethod getApproveKey];
            NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];
            [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
                NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
                NSArray *dataArray = [dic objectForKey:@"dataGrid"];
                for (NSDictionary *myDic in dataArray) {
                    self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
                    [self.tableArray addObject:self.listModel];
                }
                NSArray *otherArr = [dic objectForKey:@"other"];
                for (NSDictionary *myDic in otherArr) {
                    self.otherDic = myDic;
                    [self.otherArray addObject:self.otherDic];
                }
                [self.detailsListView.tableView reloadData];
            }];
        }
        else
        {
            [self aleareViewWithString:@"操作失败"];
        }
    }
     
     ];
}
- (void)OnlyImageTrampleReturn:(NSString *)infoId good:(NSNumber *)good bad:(NSNumber *)bad cell:(OnlyImageTableViewCell *)cell
{
    NSString *approveKey= [GlobalMethod GetIOSUUID];
    NSString *deviceParam = [GlobalMethod getApproveKey];
    NSString *body = [NSString stringWithFormat:@"infoId=%@&approveKey=%@&deviceParam=%@", infoId, approveKey, deviceParam];
    [AFNetWorkingYU netWorkWithURL:URL_ISUSO_BAD body:body resultBlock:^(id result) {
        if ([result isKindOfClass:[NSDictionary class]]) {
            
            NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
            NSString *str = [dic objectForKey:@"msg"];
            if ([str isEqualToString:@"点赞成功"]) {
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall_leffect(1)"] forState:UIControlStateNormal];
            } else if ([str isEqualToString:@"取消成功"]) {
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall(1)"] forState:UIControlStateNormal];
            }
            
            //重新网络请求
            [self.tableArray removeAllObjects];
            [self.otherArray removeAllObjects];
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString *userId = [user objectForKey:@"id"];
            //    NSString *approveKey= [GlobalMethod GetIOSUUID];
            //    NSString *deviceParam = [GlobalMethod getApproveKey];
            NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];
            [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
                NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
                NSArray *dataArray = [dic objectForKey:@"dataGrid"];
                for (NSDictionary *myDic in dataArray) {
                    self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
                    [self.tableArray addObject:self.listModel];
                }
                NSArray *otherArr = [dic objectForKey:@"other"];
                for (NSDictionary *myDic in otherArr) {
                    self.otherDic = myDic;
                    [self.otherArray addObject:self.otherDic];
                }
                [self.detailsListView.tableView reloadData];
            }];
        }
        else
        {
            [self aleareViewWithString:@"操作失败"];
        }
    }
     
     ];
}


#pragma mark - aleart
- (void)aleareViewWithString:(NSString *)message
{
    UIAlertView *aleart = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [aleart show];

}
// 信箱button事件
- (void)mailButtonAction:(UIButton *)sender
{
    NotificationViewController *notice = [[NotificationViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:notice];
    nav.navigationBar.hidden = YES;
    [self presentViewController:nav animated:YES completion:^{
        
    }];
}
//当有回复或者留言 信箱的小红点闪烁(
#pragma mark - 获取用户未读消息总数
- (void)getUnreadMessageNumber
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *signalTimer = [user objectForKey:@"timer"];
    
    NSString *key = [GlobalMethod getApproveKey];
    NSString *device = [GlobalMethod GetIOSUUID];
    
    NSString *str =[NSString stringWithFormat:@"approveKey=%@&deviceParam=%@", device, key];
    NSString *getUrl = [NSString stringWithFormat:@"%@?%@", URL_GET_UNREAD_MSG, str];
    
    [AFNetWorkingYU netWorkingHanderGetGataWithUrl:getUrl resultBlock:^(id result) {
        if ([result isKindOfClass:[NSDictionary class]]) {
            
      
        NSDictionary *dic = (NSDictionary *)result;
        NSString *str = [dic objectForKey:@"msg"];
        str = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        
        if ([[dic objectForKey:@"obj"] isKindOfClass:[NSNull class]]) {
            [dic setValue:@"" forKey:@"obj"];
        }
        if ([[dic objectForKey:@"msg"] isEqualToString:@"操作完成"]) {
            
            NSString *obj = [NSString stringWithFormat:@"%@", [dic objectForKey:@"obj"]];
            NSLog(@"%@", obj);
            //获取消息是否有未读(如果有未读  打开计时器， 没有 就关闭)
            if ([obj isEqualToString:@""] || [obj isEqualToString:@"0"] || obj == nil) {
                //判断定时器是否存在，并且判断定时器是否添加过
                if (self.detailsListView.timer && [signalTimer isEqualToString:@"1"]) {
                    [self.detailsListView removeTimer];
                    [user setObject:@"0" forKey:@"timer"];
                    //判断是否销毁过，如果销毁过 那么就可以再次添加定时器了
                }
            }
            else
            {
                if ([signalTimer isEqualToString:@"0"]) {
                    [self.detailsListView addTimer];
                    [user setObject:@"1" forKey:@"timer"];
                }
                
            }
        }
        
            
        }
        else
        {
            [self aleareViewWithString:@"操作失败"];
        }
    }];
    
}

// 定向
- (void)derectionButtonAction:(UIButton *)sender
{
    if (self.hiddenIsShow == NO) {
        [UIView animateWithDuration:0.25 animations:^{
            [self.detailsListView.hiddenView setFrame:CGRectMake(0, 64, SCREEN_WIDTH, 50)];
        } completion:^(BOOL finished) {
            self.hiddenIsShow = YES;
        }];
    } else {
        [UIView animateWithDuration:0.25 animations:^{
            [self.detailsListView.hiddenView setFrame:CGRectMake(0, 64, SCREEN_WIDTH, 0)];
        } completion:^(BOOL finished) {
            self.hiddenIsShow = NO;
        }];
    }
    
}
//发布
- (void)publishButtonAction:(UIButton *)sender
{
    
    ReleaseViewController *release = [[ReleaseViewController alloc] init];
    [self.navigationController pushViewController:release animated:YES];
}

// 类别
- (void)categoryButtonAction:(UIButton *)sender
{
    if (!_categoryIsShow) {
        [self.detailsListView.leftButton setEnabled:NO];
        [self.detailsListView bringSubviewToFront:_categoryView];
        [UIView animateWithDuration:0.2 animations:^{
            [self.detailsListView.headerView setBackgroundColor:[UIColor whiteColor]];
            [self.detailsListView.leftButton setTintColor:TEXTGREENCOLOR];
            [self.categoryView setFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
        } completion:^(BOOL finished) {
#warning 三个Button点击事件隐藏
                [self.detailsListView.leftButton setEnabled:YES];
            self.categoryIsShow = YES;
        }];
    }
    else {
        [UIView animateWithDuration:0.2 animations:^{
            [self.detailsListView.headerView setBackgroundColor:BLACKCOLOR];
            [self.detailsListView.rightButton setTintColor:[UIColor whiteColor]];
            [self.categoryView setFrame:CGRectMake(0, 64, SCREEN_WIDTH, 0)];
        } completion:^(BOOL finished) {
            [self.detailsListView.leftButton setTintColor:[UIColor whiteColor]];
#warning 三个Button点击事件恢复
            [self.detailsListView.tableView reloadData];
            self.categoryIsShow = NO;
        }];
    }
}

- (void)cateButtonAction:(id)sender
{
    UIButton * button = (UIButton *)sender;
    if (![button.titleLabel.text isEqualToString:_category]) {
        [_choiceButton setSelected:NO];
        
        [sender setSelected:YES];
    }
    self.choiceButton = button;
    self.categoryView.choiceButtonTag = button.tag;
    NSLog(@"%d", self.categoryView.choiceButtonTag);
    self.category = button.titleLabel.text;
    NSLog(@"%@", self.category);
    
    [UIView animateWithDuration:0.3 animations:^{
        [self.detailsListView.headerView setBackgroundColor:BLACKCOLOR];
        [self.detailsListView.leftButton setTintColor:[UIColor whiteColor]];
        [self.categoryView setFrame:CGRectMake(0, 64, SCREEN_WIDTH, 0)];
        _category = button.titleLabel.text;
        [_tableArray removeAllObjects];
        [_otherArray removeAllObjects];
    } completion:^(BOOL finished) {
        //重新网络请求
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString *userId = [user objectForKey:@"id"];
        NSString *approveKey= [GlobalMethod GetIOSUUID];
        NSString *deviceParam = [GlobalMethod getApproveKey];
        NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];
        
        Reachability * reach = [Reachability reachabilityWithHostname:@"www.baidu.com"];
        if ([reach currentReachabilityStatus] != NotReachable) {
            [_fontView setFrame:CGRectZero];
            [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
                if ([result isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
                    NSArray *dataArray = [dic objectForKey:@"dataGrid"];
                    for (NSDictionary *myDic in dataArray) {
                        self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
                        [self.tableArray addObject:self.listModel];
                    }
                    NSArray *otherArr = [dic objectForKey:@"other"];
                    for (NSDictionary *myDic in otherArr) {
                        self.otherDic = myDic;
                        [self.otherArray addObject:self.otherDic];
                        
                    }
                    
                    [self.detailsListView.tableView reloadData];
                    
                    // 添加类别的图片
                    NSDictionary *categoryDic = [NSDictionary dictionaryWithObjectsAndKeys:@"Mark_notice", @"tongzhi", @"Mark_Activities", @"huodong", @"Mark_Lecture", @"jiangzuo", @"Mark_Date", @"yueme", @"Mark_Match", @"bisai", @"Mark_Market", @"shichang", @"Mark_Greedy", @"chihuo", @"Mark_Students", @"shetuan", @"Mark_lover", @"tuodan", @"Mark_Retrieve", @"xunwu", @"Mark_help", @"qiuzu", @"Mark_Nonsense", @"chedan", nil];
                    if (_category == nil) {
                        [self.detailsListView.categoryButton setBackgroundImage:[UIImage imageNamed:@"Mark_All"] forState:UIControlStateNormal];
                    } else {
                        [self.detailsListView.categoryButton setBackgroundImage:[UIImage imageNamed:[categoryDic objectForKey:_category]] forState:UIControlStateNormal];
                    }
                }
                else {
#warning
                    [LoadIndicator networkStateNotReachableInView:self.view];
                }
            }];
        }
        else {
            [self.fontView setFrame:CGRectMake(0, self.detailsListView.headerView.frame.size.height, SCREEN_WIDTH, self.detailsListView.footerView.frame.origin.y - self.detailsListView.headerView.frame.size.height)];
            [_fontView setBackgroundColor:[UIColor whiteColor]];
            [self.detailsListView addSubview:_fontView];
            [LoadIndicator networkStateNotReachableInView:_fontView];
        }
        [self.detailsListView.rightButton setEnabled:YES];
#warning 三个Button点击事件恢复
        [self.detailsListView.tableView reloadData];
        self.categoryIsShow = NO;
    }];
}

// 地区选择事件
- (void)areaButtonAction:(UIButton *)sender
{
    [_tableArray removeAllObjects];
    [_otherArray removeAllObjects];
    NSString *approveKey= nil;
    NSString *deviceParam = nil;
    NSString *body = nil;
    if (_currentButton == sender) {
        [_currentButton setTitleColor:TEXTGREENCOLOR forState:UIControlStateNormal];
    }else {
        [sender setTitleColor:TEXTGREENCOLOR forState:UIControlStateNormal];
        [_currentButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    _currentButton = sender;
    
        if ([sender.titleLabel.text isEqualToString:@"全国"]) {
            body = nil;
            approveKey = @"";
            deviceParam= @"";
        } else if ([sender.titleLabel.text isEqualToString:@"本省"]) {
            approveKey= [GlobalMethod GetIOSUUID];
            deviceParam = [GlobalMethod getApproveKey];
            body = [NSString stringWithFormat:@"areaColumn=province&areaKey=mine"];
        } else if ([sender.titleLabel.text isEqualToString:@"本市"]) {
            approveKey= [GlobalMethod GetIOSUUID];
            deviceParam = [GlobalMethod getApproveKey];
            body = [NSString stringWithFormat:@"areaColumn=city&areaKey=mine"];
        } else if ([sender.titleLabel.text isEqualToString:@"本校"]) {
            approveKey= [GlobalMethod GetIOSUUID];
            deviceParam = [GlobalMethod getApproveKey];
            body = [NSString stringWithFormat:@"areaColumn=school&areaKey=mine"];
        }
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *userId = [user objectForKey:@"id"];
    NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceParam=%@&page=1&rows=10&%@&sort=pub_time&order=desc&userId=%@&category=%@", URL_GET_INFO_LIST, approveKey , deviceParam, body, userId, _category];
    [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
        if ([result isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
        NSArray *dataArray = [dic objectForKey:@"dataGrid"];
        for (NSDictionary *myDic in dataArray) {
            self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
            [self.tableArray addObject:self.listModel];
        }
        NSArray *otherArr = [dic objectForKey:@"other"];
        for (NSDictionary *myDic in otherArr) {
            self.otherDic = myDic;
            [self.otherArray addObject:self.otherDic];
        }
        
        [self.detailsListView.tableView reloadData];
        [UIView animateWithDuration:0.2 animations:^{
            [self.detailsListView.hiddenView setFrame:CGRectMake(0, 64, SCREEN_WIDTH, 0)];
        } completion:^(BOOL finished) {
            self.hiddenIsShow = NO;
        }];
        }
        else {
#warning 
            [LoadIndicator networkStateNotReachableInView:self.view];
        }
    }];
}


- (void)startConnect
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *userId = [user objectForKey:@"id"];
    NSString *approveKey= [GlobalMethod GetIOSUUID];
    NSString *deviceParam = [GlobalMethod getApproveKey];
    NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];

    Reachability * reach = [Reachability reachabilityWithHostname:@"www.baidu.com"];
    if ([reach currentReachabilityStatus] != NotReachable) {
        [self.fontView setFrame:CGRectZero];
        [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
            if ([result isKindOfClass:[NSDictionary class]]) {
                NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
                NSArray *dataArray = [dic objectForKey:@"dataGrid"];
                for (NSDictionary *myDic in dataArray) {
                    self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
                    [self.tableArray addObject:self.listModel];
                }
                NSArray *otherArr = [dic objectForKey:@"other"];
                for (NSDictionary *myDic in otherArr) {
                    self.otherDic = myDic;
                    [self.otherArray addObject:self.otherDic];
                }
                
                [self.detailsListView creatView];
                [self.view addSubview:_detailsListView];
                [self.detailsListView.tableView reloadData];
                // 添加类别的图片
                NSDictionary *categoryDic = [NSDictionary dictionaryWithObjectsAndKeys:@"Mark_notice", @"tongzhi", @"Mark_Activities", @"huodong", @"Mark_Lecture", @"jiangzuo", @"Mark_Date", @"yueme", @"Mark_Match", @"bisai", @"Mark_Market", @"shichang", @"Mark_Greedy", @"chihuo", @"Mark_Students", @"shetuan", @"Mark_lover", @"tuodan", @"Mark_Retrieve", @"xunwu", @"Mark_help", @"qiuzu", @"Mark_Nonsense", @"chedan", nil];
                if (_category == nil) {
                    [self.detailsListView.categoryButton setBackgroundImage:[UIImage imageNamed:@"Mark_All"] forState:UIControlStateNormal];
                } else {
                    [self.detailsListView.categoryButton setBackgroundImage:[UIImage imageNamed:[categoryDic objectForKey:_category]] forState:UIControlStateNormal];
                }
                // tableView设置代理
                self.detailsListView.tableView.delegate = self;
                self.detailsListView.tableView.dataSource = self;
                
                [self.detailsListView.categoryButton addTarget:self action:@selector(categoryButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                // 通知事件
                [self.detailsListView.mailButton addTarget:self action:@selector(mailButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                // 全国
                [self.detailsListView.hiddenView.countryButton addTarget:self action:@selector(areaButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                // 本省
                [self.detailsListView.hiddenView.provinceButton addTarget:self action:@selector(areaButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                // 本市
                [self.detailsListView.hiddenView.cityButton addTarget:self action:@selector(areaButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                // 本校
                [self.detailsListView.hiddenView.schoolButton addTarget:self action:@selector(areaButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                self.index = 2;
                [self startRefresh];
                [self addfooterRefresh];
            } else {

                [LoadIndicator networkStateNotReachableInView:self.view];
        
            }
        }];
    }
    else {
        [self.fontView setFrame:CGRectMake(0, self.detailsListView.headerView.frame.size.height, SCREEN_WIDTH, self.detailsListView.footerView.frame.origin.y - self.detailsListView.headerView.frame.size.height)];
        [_fontView setBackgroundColor:[UIColor whiteColor]];
        [self.detailsListView addSubview:_fontView];
        [LoadIndicator networkStateNotReachableInView:_fontView];
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailModel *model = [self.tableArray objectAtIndex:indexPath.row];
    if ([model.category isEqualToString:@"视频"] || [model.category isEqualToString:@"公告"]) {
        return 80.0f;
    } else if ([model.content isEqualToString:@""] && model.img != nil) {
        return 160.0f;
    } else if (model.img == nil && ![model.content isEqualToString:@""]) {
        return 128.0f;
    } else if (model.img != nil && ![model.content isEqualToString:@""]) {
        return 192.0f;
    } else {
        return 128.0f;
    }
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"tableArray Count ====== %d", _tableArray.count);
    return [self.tableArray count] - 1;
}
// tableView的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailModel *model = [self.tableArray objectAtIndex:indexPath.row];
    NSDictionary *dic = [self.otherArray objectAtIndex:indexPath.row];
    if ([model.category isEqualToString:@"视频"] || [model.category isEqualToString:@"公告"]) {
        CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"customCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        [cell setSeparatorInset:UIEdgeInsetsZero];
        [cell setLayoutMargins:UIEdgeInsetsZero];
        // 获取头像url
        NSString *imgUrl = [NSString stringWithFormat:@"http://www.isu.so/attached/u_img/%@", model.puberImg];
        [cell.headerImage sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        [cell.headerButton setTitle:model.puberId forState:UIControlStateNormal];
        [cell.headerButton addTarget:self action:@selector(headerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        // 获取标题
        NSString *titleStr = [GlobalMethod replaceCharacterWithString:model.title];
        NSMutableAttributedString *string =[[NSMutableAttributedString alloc]initWithString:titleStr];
        long number = 0.5;
        CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt8Type,&number);
        [string addAttribute:(id)kCTKernAttributeName value:(__bridge id)num range:NSMakeRange(0,[string length])];
        CFRelease(num);
        
        [cell.titleLabel setAttributedText:string];
        // 获取认证信息
        NSString *puberInfo = [GlobalMethod puberNickChangeString:model.puberRole];
        [cell.infoLabel setText:puberInfo];
        NSString *school = [NSString stringWithFormat:@" • %@",model.puberSchool];
        if (iPhone5) {
            if ([school length] > 8) {
                school = [[school substringToIndex:8] stringByAppendingString:@"..."];
            }
        }
        [cell.puberSchool setText:school];
        [cell.timeLabel setText:model.pubTime];
        [cell.nameLabel setText:model.puberNick];
        NSString *categoryText = [NSString stringWithFormat:@"%@ • ", model.category];
        [cell.styleLabel setText:categoryText];
        return cell;
    } else if (model.img != nil && [model.content isEqualToString:@""]) {
        OnlyImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"imageCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        // 判断踩或赞的状态
            if ([[dic objectForKey:@"good"] isEqual:@(NO)]){
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall(1)"] forState:UIControlStateNormal];
                
            }else if ([[dic objectForKey:@"good"] isEqual:@(YES)]){
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall_effect(1)"] forState:UIControlStateNormal];
                
            }
            if ([[dic objectForKey:@"bad"] isEqual:@(NO)]){
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall(1)"] forState:UIControlStateNormal];
                
            }else if ([[dic objectForKey:@"bad"] isEqual:@(YES)]){
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall_leffect(1)"] forState:UIControlStateNormal];
            }
        cell.delegate = self;
        [cell setSeparatorInset:UIEdgeInsetsZero];
        [cell setLayoutMargins:UIEdgeInsetsZero];
        // 获取头像url
        cell.infoId = model.id;
        cell.good = model.good;
        cell.bad = model.bad;
        NSString *imgUrl = [NSString stringWithFormat:@"http://www.isu.so/attached/u_img/%@", model.puberImg];
        [cell.headerImage sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        [cell.headerButton setTitle:model.puberId forState:UIControlStateNormal];
        [cell.headerButton addTarget:self action:@selector(headerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        // 获取标题
        NSString *titleStr = [GlobalMethod replaceCharacterWithString:model.title];
        [cell.titleLabel setText:titleStr];
        // 获取认证信息
        NSString *puberInfo = [GlobalMethod puberNickChangeString:model.puberRole];
        [cell.infoLabel setText:puberInfo];
        NSString *school = [NSString stringWithFormat:@" • %@",model.puberSchool];
        if (iPhone5) {
            if ([school length] > 10) {
                school = [[school substringToIndex:10] stringByAppendingString:@"..."];
            }
        }
        [cell.puberSchool setText:school];
        [cell.timeLabel setText:model.pubTime];
        [cell.nameLabel setText:model.puberNick];
        // 类别
        NSString *categoryText = [NSString stringWithFormat:@"%@ • ", model.category];
        [cell.styleLabel setText:categoryText];
        
        [cell.infoImage sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        [cell.infoImageButton setTitle:model.img forState:UIControlStateNormal];
        [cell.infoImageButton addTarget:self action:@selector(infoImageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        
        
        // 点赞/踩数
        NSString *priStr = [NSString stringWithFormat:@"%@", model.good];
        NSString *traStr = [NSString stringWithFormat:@"%@", model.bad];
        
        [cell.priseLabel setText:priStr];
        [cell.trampleLabel setText:traStr];
        return cell;
    } else if (model.img == nil && ![model.content isEqualToString:@""]) {
        OnlyTextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"textCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        [cell setSeparatorInset:UIEdgeInsetsZero];
        [cell setLayoutMargins:UIEdgeInsetsZero];
        cell.delegate = self;
        cell.infoId = model.id;
        cell.good = model.good;
        cell.bad = model.bad;
        
        // 判断踩或赞的状态
            
            if ([[dic objectForKey:@"good"] isEqual:@(NO)]){
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall(1)"] forState:UIControlStateNormal];
                
            }else if ([[dic objectForKey:@"good"] isEqual:@(YES)]){
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall_effect(1)"] forState:UIControlStateNormal];
                
            }
            if ([[dic objectForKey:@"bad"] isEqual:@(NO)]){
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall(1)"] forState:UIControlStateNormal];
                
            }else if ([[dic objectForKey:@"bad"] isEqual:@(YES)]){
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall_leffect(1)"] forState:UIControlStateNormal];
            }
        
        // 获取头像url
        NSString *imgUrl = [NSString stringWithFormat:@"http://www.isu.so/attached/u_img/%@", model.puberImg];
        [cell.headerImage sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        [cell.headerButton setTitle:model.puberId forState:UIControlStateNormal];
        [cell.headerButton addTarget:self action:@selector(headerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        // 获取标题
        NSString *titleStr = [GlobalMethod replaceCharacterWithString:model.title];
        [cell.titleLabel setText:titleStr];
        // 获取认证信息
        NSString *puberInfo = [GlobalMethod puberNickChangeString:model.puberRole];
        [cell.infoLabel setText:puberInfo];
        NSString *school = [NSString stringWithFormat:@" • %@",model.puberSchool];
        if (iPhone5) {
            if ([school length] > 10) {
                school = [[school substringToIndex:10] stringByAppendingString:@"..."];
            }
        }
        NSString *text = [model.content stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@" "];
        if ([text length] <= 30) {
            text = text;
        } else {
            text = [[text substringToIndex:30
                    ] stringByAppendingString:@"..."];
        }
        [cell.infoTextLabel setText:text];
        [cell.puberSchool setText:school];
        [cell.timeLabel setText:model.pubTime];
        [cell.nameLabel setText:model.puberNick];
        // 类别
        NSString *categoryText = [NSString stringWithFormat:@"%@ • ", model.category];
        [cell.styleLabel setText:categoryText];
        
        // 点赞/踩数
        NSString *priStr = [NSString stringWithFormat:@"%@", model.good];
         NSString *traStr = [NSString stringWithFormat:@"%@", model.bad];
        [cell.priseLabel setText:priStr];
        [cell.trampleLabel setText:traStr];
        return cell;
    } else if (model.img != nil && ![model.content isEqualToString:@""]) {
        TextAndImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"textAndImageCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        cell.delegateA = self;
        cell.infoId = model.id;
        cell.good = model.good;
        cell.bad = model.bad;
        [cell setSeparatorInset:UIEdgeInsetsZero];
        [cell setLayoutMargins:UIEdgeInsetsZero];
        
        // 判断踩或赞的状态
            
            if ([[dic objectForKey:@"good"] isEqual:@(NO)]){
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall(1)"] forState:UIControlStateNormal];
                
            }else if ([[dic objectForKey:@"good"] isEqual:@(YES)]){
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall_effect(1)"] forState:UIControlStateNormal];
                
            }
            if ([[dic objectForKey:@"bad"] isEqual:@(NO)]){
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall(1)"] forState:UIControlStateNormal];
                
            }else if ([[dic objectForKey:@"bad"] isEqual:@(YES)]){
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall_leffect(1)"] forState:UIControlStateNormal];
            }
        
        // 获取头像url
        NSString *imgUrl = [NSString stringWithFormat:@"http://www.isu.so/attached/u_img/%@", model.puberImg];
        [cell.headerImage sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        [cell.headerButton setTitle:model.puberId forState:UIControlStateNormal];
        [cell.headerButton addTarget:self action:@selector(headerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        // 获取标题
        NSString *titleStr = [GlobalMethod replaceCharacterWithString:model.title];
        [cell.titleLabel setText:titleStr];
        // 获取认证信息
        NSString *puberInfo = [GlobalMethod puberNickChangeString:model.puberRole];
        [cell.infoLabel setText:puberInfo];
        NSString *school = [NSString stringWithFormat:@" • %@",model.puberSchool];
        if (iPhone5) {
            if ([school length] > 10) {
                school = [[school substringToIndex:10] stringByAppendingString:@"..."];
            }
        }
        [cell.puberSchool setText:school];
        [cell.timeLabel setText:model.pubTime];
        [cell.nameLabel setText:model.puberNick];
        // 类别
        NSString *categoryText = [NSString stringWithFormat:@"%@ • ", model.category];
        [cell.styleLabel setText:categoryText];
        
        NSString *text = [model.content stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@" "];
        [cell.infoTextLabel setText:text];
        
        [cell.infoImage sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        [cell.infoImageButton setTitle:model.img forState:UIControlStateNormal];
        [cell.infoImageButton addTarget:self action:@selector(infoImageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        // 点赞/踩数
        NSString *priStr = [NSString stringWithFormat:@"%@", model.good];
        NSString *traStr = [NSString stringWithFormat:@"%@", model.bad];
        [cell.priseLabel setText:priStr];
        [cell.trampleLabel setText:traStr];
        return cell;
    }
    else
    {
        OnlyTextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"textCell"];
        [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
        cell.delegate = self;
        cell.infoId = model.id;
        cell.good = model.good;
        cell.bad = model.bad;
        
        // 判断踩或赞的状态
            
            if ([[dic objectForKey:@"good"] isEqual:@(NO)]){
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall(1)"] forState:UIControlStateNormal];
                
            }else if ([[dic objectForKey:@"good"] isEqual:@(YES)]){
                [cell.praiseButton setBackgroundImage:[UIImage imageNamed:@"Button_Praisesmall_effect(1)"] forState:UIControlStateNormal];
                
            }
            if ([[dic objectForKey:@"bad"] isEqual:@(NO)]){
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall(1)"] forState:UIControlStateNormal];
                
            }else if ([[dic objectForKey:@"bad"] isEqual:@(YES)]){
                [cell.trampleButton setBackgroundImage:[UIImage imageNamed:@"Button_Belittlesmall_leffect(1)"] forState:UIControlStateNormal];
            }
        
        // 获取头像url
        NSString *imgUrl = [NSString stringWithFormat:@"http://www.isu.so/attached/u_img/%@", model.puberImg];
        [cell.headerImage sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        [cell.headerButton setTitle:model.puberId forState:UIControlStateNormal];
        [cell.headerButton addTarget:self action:@selector(headerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        // 获取标题
        NSString *titleStr = [GlobalMethod replaceCharacterWithString:model.title];
        [cell.titleLabel setText:titleStr];
        // 获取认证信息
        NSString *puberInfo = [GlobalMethod puberNickChangeString:model.puberRole];
        [cell.infoLabel setText:puberInfo];
        NSString *school = [NSString stringWithFormat:@" • %@",model.puberSchool];
        if (iPhone5) {
            if ([school length] > 10) {
                school = [[school substringToIndex:10] stringByAppendingString:@"..."];
            }
        }
        [cell.infoTextLabel setText:model.content];
        [cell.puberSchool setText:school];
        [cell.timeLabel setText:model.pubTime];
        [cell.nameLabel setText:model.puberNick];
        // 类别
        NSString *categoryText = [NSString stringWithFormat:@"%@ • ", model.category];
        [cell.styleLabel setText:categoryText];
        
        // 点赞/踩数
        NSString *priStr = [NSString stringWithFormat:@"%@", model.good];
        NSString *traStr = [NSString stringWithFormat:@"%@", model.bad];
        [cell.priseLabel setText:priStr];
        [cell.trampleLabel setText:traStr];
        return cell;
    }
    return nil;
}
// 头像点击事件
- (void)headerButtonAction:(UIButton *)sender
{
    OtherPersonViewController *otherPersonal = [[OtherPersonViewController alloc] init];
    otherPersonal.puberId = sender.titleLabel.text;
    [self.navigationController pushViewController:otherPersonal animated:YES];
}

- (void)infoImageButtonAction:(UIButton *)sender
{
    ImageShowViewController *show = [[ImageShowViewController alloc] init];
    show.imgUrl = sender.titleLabel.text;
    [self.navigationController pushViewController:show animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.detailsListView.tableView deselectRowAtIndexPath:indexPath animated:NO];
    DetailViewController *detail = [[DetailViewController alloc] init];
    DetailModel *model = [_tableArray objectAtIndex:indexPath.row];
    NSDictionary *other = [_otherArray objectAtIndex:indexPath.row];
    detail.model = model;
    detail.otherDic = other;
    [self.navigationController pushViewController:detail animated:YES];
    
}

// 刷新/加载
- (void)startRefresh
{
    [self.detailsListView.tableView addHeaderWithCallback:^{
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString *userId = [user objectForKey:@"id"];
        NSString *approveKey= [GlobalMethod GetIOSUUID];
        NSString *deviceParam = [GlobalMethod getApproveKey];
        NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=1&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, _category, userId];
        [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
            [self.tableArray removeAllObjects];
            [self.otherArray removeAllObjects];
            if ([result isKindOfClass:[NSDictionary class]]) {
                NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
                NSArray *dataArray = [dic objectForKey:@"dataGrid"];
                
                for (NSDictionary *myDic in dataArray) {
                    self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
                    [self.tableArray addObject:self.listModel];
                }
                NSArray *otherArr = [dic objectForKey:@"other"];
                for (NSDictionary *myDic in otherArr) {
                    self.otherDic = myDic;
                    [self.otherArray addObject:self.otherDic];

                }
            }
            else {
#warning
                [LoadIndicator networkStateNotReachableInView:self.view];
            }
            
        }];
        [self.detailsListView.tableView reloadData];
        [self.detailsListView.tableView headerEndRefreshing];
        
        //小红点数据刷新（实时：杜）
        [self getUnreadMessageNumber];
        self.index = 2;
    }];
}
- (void)addfooterRefresh
{
        [self.detailsListView.tableView addFooterWithCallback:^{
            [self.tableArray removeAllObjects];
            [self.otherArray removeAllObjects];
            if (self.index < 40) {
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString *userId = [user objectForKey:@"id"];
            NSString *approveKey= [GlobalMethod GetIOSUUID];
            NSString *deviceParam = [GlobalMethod getApproveKey];
            NSString *url = [NSString stringWithFormat:@"%@?approveKey=%@&deviceId=%@&page=%ld&rows=20&category=%@&userId=%@", URL_GET_INFO_LIST,approveKey, deviceParam, self.index,_category, userId];
            [AFNetWorkingYU netWorkingHanderGetGataWithUrl:url resultBlock:^(id result) {
                if ([result isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
                NSArray *dataArray = [dic objectForKey:@"dataGrid"];
                for (NSDictionary *myDic in dataArray) {
                    self.listModel = [[DetailModel alloc] initWithDictionary:myDic];
                    [self.tableArray addObject:self.listModel];
                }
                    NSArray *otherArr = [dic objectForKey:@"other"];
                    for (NSDictionary *myDic in otherArr) {
                        self.otherDic = myDic;
                        [self.otherArray addObject:self.otherDic];
                    }
                }
                else {
#warning
                    [LoadIndicator networkStateNotReachableInView:self.view];
                }
                
            }];
            [self.detailsListView.tableView reloadData];
            [self.detailsListView.tableView footerEndRefreshing];
            //小红点数据刷新（实时：杜）
            [self getUnreadMessageNumber];
                self.index++;
            }
        }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
